<template>
  <!-- 费用（条码申请项目） -->
  <div id="wLapplicationItem">
    <div class="radius margin-xs solid line-grey padding-xs">
      <el-steps style="width: 100%" :active="bacActive" align-center>
        <el-step title="" v-for="(m, i) in bacCultiObserList" :key="i" :class="m.isActive ? 'bg-grey light radius' : ''" @click="bacCultiObserItemClick(m)">
          <!-- <template #icon>
            <div>
              <span class="el-step__icon is-text" style="background: rgba(0, 0, 0, 0)">{{ `${i}` }}</span>
            </div>
          </template> -->
          <template #title>
            <span class="text-cut">{{ m.strainName ? m.strainName : '' }}</span>
          </template>
        </el-step>
      </el-steps>
    </div>
    <div :style="{ height: `calc(100% - ${props.businessType!=''?props.businessType==='node1'?'310px':props.businessType==='node2'?'130px':'190px':'0px'})` }">
      <vxe-table ref="applicationItemTableList" v-loading="loading" border height="auto" :data="bacStrainLogList" :merge-footer-items="[{ row: 0, col: 1, rowspan: 1, colspan: 5 }]" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{
          isArrow: true,
          isTab: true,
          isEdit: true
        }" footer-row-class-name="table-footer" show-footer resizable show-overflow>
        <vxe-column field="createTime" title="操作时间" width="120"></vxe-column>
        <vxe-column field="content" title="操作内容" align="left" min-width="260"></vxe-column>
        <vxe-column field="operatorNa" title="操作人" width="60" align="left"></vxe-column>
      </vxe-table>
    </div>
  </div>
</template>
<script setup lang="ts">
import { getCurrentInstance, reactive, ref, onMounted } from 'vue';
import { formatDateTime, IsEmpty } from '@/utils/common';
import 'vxe-table/lib/style.css';

let { proxy }: any = getCurrentInstance();

const props = defineProps({
  businessType: {
    type: String,
    default: ''
  }
});

let loading = ref(false);
let applicationItemTableList = ref(null);
let labMainInfoObj: any = reactive({}); /**检验记录当前选中对象 */
let stepNodeObj: any = reactive({}); /**当前选中流程节点对象 */
let bacCultiObserList: any[] = reactive([]); /**细菌菌株 */
let bacStrainLogList: any[] = reactive([]); /**细菌过程记录集合 */
let bacActive = ref(5); /**当前选中第几珠菌 */

defineExpose({
  initRecords
});

/**初始化界面 */
function initRecords(mainInfoRow: any, stepNode: any) {
  Object.assign(labMainInfoObj, mainInfoRow);
  Object.assign(stepNodeObj, stepNode);
  findRptCultiObserResult();
}

/**查询菌株 */
function findRptCultiObserResult() {
  console.log('findRptCultiObserResult-查询过程记录');
  bacCultiObserList.length = 0;
  if (IsEmpty(labMainInfoObj.rptGroup) || IsEmpty(labMainInfoObj.sampleda) || IsEmpty(labMainInfoObj.sampleNo)) {
    return;
  }
  const url = '/bac/strain/findStrain';
  let data = { mainInfoId: labMainInfoObj.id, rptGroup: labMainInfoObj.rptGroup, sampleda: formatDateTime(labMainInfoObj.sampleda, 'yyyy-MM-dd 00:00:00'), sampleNo: labMainInfoObj.sampleNo } as any;
  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      if (res && res.data && res.data.length >= 0) {
        bacCultiObserList.push({ id: '', strainName: '全部' });
        bacCultiObserList.push(...res.data);
        bacCultiObserItemClick(bacCultiObserList[0]);
      }
    })
    .catch((err: any) => { });
}
/**菌株点击事件 */
function bacCultiObserItemClick(m) {
  bacCultiObserList.forEach((e, i) => {
    if (e.id === m.id) {
      e.isActive = true;
    } else {
      e.isActive = false;
    }
  });
  findBacStrainLog(m);
}
/**查询log */
function findBacStrainLog(m) {
  bacStrainLogList.length = 0;
  if (IsEmpty(labMainInfoObj.sampleda) || IsEmpty(labMainInfoObj.rptGroup) || IsEmpty(labMainInfoObj.sampleNo) || IsEmpty(labMainInfoObj.testFlowNo) || IsEmpty(labMainInfoObj.nodeNo)) {
    return;
  }

  const url = '/bac/strainLog/findStrainLogList';
  let data = {
    maininfoId: labMainInfoObj.id,
    rptGroup: labMainInfoObj.rptGroup,
    sampleda: formatDateTime(labMainInfoObj.sampleda, 'yyyy-MM-dd 00:00:00'),
    sampleNo: labMainInfoObj.sampleNo,
    //wkFlwId: stepNodeObj.workFlowId,
    testFlowNo: labMainInfoObj.testFlowNo,
    //wkFlwNodeId: stepNodeObj.workFlowNodeId,
    testNodeNo: labMainInfoObj.nodeNo,
    //strainId: m.id,
    strainNo: IsEmpty(m) ? null : m.strainNo
  };
  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      if (res && res.data && res.data.length >= 0) {
        bacStrainLogList.push(...res.data);
      }
    })
    .catch((err: any) => { });
}
</script>
<style lang="scss" scoped>
#wLapplicationItem {
  height: 100%;

  :deep(.el-steps .el-step .el-step__head) {
    color: pink !important;
    display: none !important;
    border: 2px solid #fff;
    border-radius: 50%;
  }
  //:nth-child(1)
  :deep(.el-steps .el-step .el-step__main .el-step__title) {
    font-size: 19px;
  }

  :deep(.el-step__head) {
    display: none;
  }
}
</style>
